package pers.gxm.adapter;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class FileProperties extends Properties implements FileIO  {
    public static void main(String[] args) {
        String property = System.getProperty("user.dir");
        System.out.println("property = " + property);

        FileIO f = new FileProperties();
        try {
            f.readFromFile("src/main/resources/adapter/file.txt");
            String year = f.getValue("year");
            System.out.println("year = " + year);
            f.setValue("year","2024");
            f.setValue("month","1");
            f.setValue("day","14");
            f.setValue("hour","14");
            f.writeToFile("src/main/resources/adapter/newFile.txt");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
    @Override
    public void readFromFile(String filename) throws IOException {
        load(new FileReader(filename));
    }

    @Override
    public void writeToFile(String filename) throws IOException {
        store(new FileWriter(filename),null);
    }

    @Override
    public void setValue(String key, String value) {
        setProperty(key,value);
    }

    @Override
    public String getValue(String key) {
        return getProperty(key);
    }
}
